<template>
  <div class="container" ref="barrageContent">
    <div class="log">
      <div>logo</div>
      <div>在线教育后台</div>
    </div>
    <div class="forms-container">
      <div class="signin-signup">
        <form action="#" class="sign-in-form">
          <div class="input-field">
            <i class="fas fa-user"></i>
            <input type="text" placeholder="请输入用户名/手机号" autocomplete="on" v-model="fromdata.form.name" />
          </div>
          <div class="input-field">
            <i class="fas fa-lock"></i>
            <input type="password" placeholder="请输入密码" autocomplete="on" v-model="fromdata.form.pwd" />
          </div>
          <div class="huakuai">
            <Vcode :imgs="datas.imglist" :show="isShow" @success="onSuccess" @close="onClose" />
          </div>
          <input value="立即登录" class="btn solid btn_login" @click="login" />
        </form>
      </div>
    </div>
  </div>
</template>

<script setup>
import Vcode from "vue3-puzzle-vcode";
import { getCurrentInstance, ref, reactive } from "vue";
import { useRouter } from "vue-router";
import { useStore } from "vuex";
import { ElMessageBox, ElMessage } from "element-plus";
const datas = reactive({
  imglist: [
    "https://img0.baidu.com/it/u=1275095085,1961143463&fm=253&fmt=auto&app=120&f=JPEG?w=1280&h=800",
    "https://img2.baidu.com/it/u=3219906533,2982923681&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500"
  ]
})
const { proxy } = getCurrentInstance();
const isShow = ref(false)
const submit = (msg) => {
  isShow.value = true;
}
// 用户通过了验证
const success = (msg) => {
  isShow.value = false; // 通过验证后，需要手动隐藏模态框
}
// 用户点击遮罩层，应该关闭模态框
const close = () => {
  isShow.value = false;
}
// 用户验证失败
const fail = () => {
  console.log('验证失败');
}
const widths = ref(100)
const router = useRouter();
const fromdata = reactive({form:{
  name: "",
  pwd: "",
}})
const login = async () => {
  isShow.value = true;
};


const onShow = () => {
  isShow.value = true;
};

const onClose = () => {
  isShow.value = false;
};

const onSuccess = async () => {
  console.log(fromdata, 666);
  let data = await proxy.axios.post("ljf/login", fromdata.form)
  if (data.data.code === 200) {
    ElMessageBox.alert('登录成功', '登录提示', {
      confirmButtonText: '进入',
      callback: () => {
        ElMessage({
          type: 'info',
          message: `登录成功`,
        })
        router.push("/welcome");
      },
    })
  } else {
    ElMessageBox.alert('登录失败', '登录提示', {
      confirmButtonText: '重新输入',
      callback: () => {
        fromdata.name = ""
        fromdata.pwd = ""
        ElMessage({
          type: 'warning',
          message: `登录失败`,
        })
      },
    })
  }

  onClose(); // 验证成功，手动关闭模态框
};


</script>


<style scoped >
.log {
  border-top-right-radius: 0px !important;
  border-bottom-right-radius: 0px !important;
  border-radius: 15px;
  width: 420px;
  height: 470px;
  background-color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.log div:first-child {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  font-size: 32px;
  display: flex;
  margin-bottom: 15px;
  align-items: center;
  justify-content: center;
  width: 100px;
  height: 100px;
  background-color: #3778ff;
  border-radius: 50%;
}

.log div:last-child {
  font-size: 30px;
  font-weight: bold;
}

.huakuai {
  text-align: left !important;
}

@keyframes moveLeft {
  from {
    left: 0px;
  }

  to {}
}

@keyframes moveRight {
  from {
    right: 0px;
  }

  to {}
}

.barrage {
  display: block;
  position: absolute;
  animation: right2left 16s cubic-bezier(0.44, 0.4, 1, 1) forwards;
  font-size: 1.35vw;
  font-family: Microsoft YaHei UI;
  font-weight: bold;
  color: #4a4a4a;
  /* 不定宽就会导致span一开始很窄 字会强制换行 */
  width: 150vw;
}



.btn_login {
  text-align: center;
}


body {
  width: 100px;
  height: 100px;

}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body,
input {
  font-family: "Poppins", sans-serif;
}

.container {
  width: 100vw;
  min-height: 100vh;
  background-color: #3778ff;
  display: flex;
  justify-content: center;
  align-items: center;
}

.forms-container {
  display: flex;
  justify-content: center;
  align-items: center;
}

.signin-signup {
  border-radius: 25px;
  background-color: #fff;
  width: 400px;
  height: 530px;
  border: 1px solid #eee;
}

.sign-in-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.input-field {
  width: 300px;
  height: 45px;
  margin-bottom: 15px;
}

.input-field input {
  width: 100%;
  height: 100%;
  border: none;
  background-color: rgba(0, 0, 0, 0.05);
  outline: none;
  border-radius: 10px;
  text-indent: 20px;
  font-size: 20px;
  color: #666363;
}

.btn_login {
  height: 45px;
  border: none;
  background-color: #3778ff;
  width: 300px;
  margin-top: 20px;
  border-radius: 15px;
  font-size: 20px;
  outline: none;
  color: #fff;
}

.panels-container {
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;
}

.content i {
  font-size: 40px;
}

.panel {
  margin-bottom: 200px;
  margin-left: 200px;
}</style>